package sigcBeans;

import com.franz.agbase.AllegroGraphException;
import java.util.*;
import agraph.*;

public class userBean{
	
	
	public userBean() {}

	AGraph ag = new AGraph();
	UserHandling uh = new UserHandling();
	
String txtLogin;
String txtPasswd;

public boolean fazLogin(String txtLogin,String txtPasswd) throws AllegroGraphException{
	if(uh.userLogin(ag, txtLogin, txtPasswd))
		return true;
		else
	return false;
}

public Vector<String> getCategorias() throws AllegroGraphException{
	Vector<String> vec = new Vector<String>();	

	vec = uh.getCategories();
	return vec;
}

public Hashtable<String,String> getOrderedCategorias() throws AllegroGraphException{
	Hashtable<String,String> hash = new Hashtable<String,String>();	

	hash = uh.getOrderedCategories();
	return hash;
}

public void registaUtilizador(String login,String passwd,String primNome,String ultNome,String eMail) throws AllegroGraphException{
	uh.userRegister(ag, eMail,login, passwd,primNome,ultNome) ;
}

public void subscreveUtil(String login,String categoria) throws AllegroGraphException{
	uh.userSubscribe(ag, login, categoria);
}

public void desSubscreveUtil(String login,String categoria) throws AllegroGraphException{
	uh.userUnsubscribe(ag, login, categoria);
}

public Vector<String> getSubscricoes(String login) throws AllegroGraphException{
	return uh.getSubscricoes(login);
}

public Vector<Hashtable> getFeedFromCategory(String category) throws AllegroGraphException{
	return uh.getFeedFromCategory(category);
}

public Vector<Hashtable> getUnreadFeedFromCategory(String category, String login) throws AllegroGraphException{
	return uh.getUnreadFeedFromCategory(category, login);//getFeedFromCategory(category);
}

/**
 * 
 * @param login
 * @return
 * @throws AllegroGraphException
 */
public int getNumberOfNewFeeds(String login) throws AllegroGraphException{
int numberOfNewFeeds = 0;
Vector<String> categorias = new Vector<String>();
Vector<Hashtable> vec = new Vector<Hashtable>();

categorias = getSubscricoes(login);
System.out.println("getNumberOfNewFeeds");
	for(String s : categorias){
		 s = s.substring(45);
		  s = s.substring(0,(s.length()-2));
		vec = getUnreadFeedFromCategory(s,login);
		numberOfNewFeeds += vec.size();
		System.out.println("getNumberOfNewFeeds"+numberOfNewFeeds+" categoria: "+s+" size:"+vec.size());
	}

return numberOfNewFeeds;
}

public void setFeedAsRead(String feedID,String login) throws AllegroGraphException{
	uh.setFeedAsRead(feedID, login);
}

public void setFeedsAsNonRead(String login) throws AllegroGraphException{
	uh.setFeedsAsNonRead(login);
}

public String getTxtLogin() {
	return txtLogin;
}
public void setTxtLogin(String txtLogin) {
	this.txtLogin = txtLogin;
}
public String getTxtPasswd() {
	return txtPasswd;
}
public void setTxtPasswd(String txtPasswd) {
	this.txtPasswd = txtPasswd;
}


}